var util = require('../../utils/util.js');
var config = require('../../config');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputVal: '',
    historyKeywords: [],
    goodsInfo:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  delStorage: function() {
    wx.setStorageSync("historyKeywords", []);
    this.setData({
      historyKeywords: []
    })
  },

  search:function(e) {
    var that = this;
    wx.showLoading({
      title: '搜索中',
    })
    var keywords = e.detail.value;
    var historyKeywords = wx.getStorageSync("historyKeywords") ? wx.getStorageSync("historyKeywords") : [];
    if (keywords) historyKeywords = historyKeywords.concat(keywords);
    if (historyKeywords.length > 10) historyKeywords = historyKeywords.slice(-12);
    wx.setStorageSync("historyKeywords", historyKeywords);
    that.setData({
      historyKeywords: historyKeywords.reverse()
    })
    app.wxPost(app.globalData.host + '/info/searchGoods', { keyword: keywords}).then(res=>{
      wx.hideLoading()
      that.setData({
        goodsInfo: res
      })
    },msg=>{
      wx.hideLoading()
      app.showToastNone(msg,2000)
    })
  }
})